{% extends 'demo/base.html' %}
{% load static %}
{% block link %}
    <link rel="stylesheet" href="{% static 'css/demo/update_article.css' %}">
{% endblock %}

{% block title %}
    修改文章 - {{ article.title }}
{% endblock %}

{% block header %}
    {% include 'demo/header.html' %}
{% endblock %}

{% block main %}
<div class="container">
    <h1>修改文章</h1>
    <form method="post" enctype="multipart/form-data">
        {% csrf_token %}
        <div class="form-group">
            <label for="title">标题:</label>
            <input type="text" class="form-control" id="title" name="title" value="{{ article.title }}" required>
        </div>
        <div class="form-group">
            <label for="desc">描述:</label>
            <textarea class="form-control" id="desc" name="desc" rows="3" required>{{ article.desc }}</textarea>
        </div>
        <div class="form-group">
            <label for="content">内容:</label>
            <textarea class="form-control" id="content" name="content" rows="10" required>{{ article.content }}</textarea>
        </div>
        <div class="form-group">
            <label for="cover">封面:</label>
            <input type="file" class="form-control-file" id="cover" name="cover">
            {% if article.cover %}
                <img src="/static/media/{{ article.cover }}/" alt="当前封面" style="max-width: 200px; margin-top: 10px;">
            {% endif %}
        </div>
        {# 文章分类 #}
        <div class="form-group">
            <label for="classes">分类:</label>
            <select class="form-control" id="classes" name="classes">
                {% for cls in classes %}
                    <option value="{{ cls.id }}" {% if cls.id == article.classes.id %}selected{% endif %}>{{ cls.name }}</option>
                {% endfor %}
            </select>
        </div>
        {# 文章标签 #}
        <div class="form-group">
            <label for="label">标签:</label>
            <select class="form-control" id="label" name="label" multiple>
                {% for label in labels %}
                    <option value="{{ label.id }}" {% if label in article.label.all %}selected{% endif %}>{{ label.name }}</option>
                {% endfor %}
            </select>
        </div>
        <input type="submit" value='保存修改' class="btn btn-primary">
    </form>
</div>
{% endblock %}
